package cn.sccl.test.criteria;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.junit.Test;

import cn.sccl.domain.Customer;
import cn.sccl.utils.HibernateUtils;

/**
 * @author raoshuang
 * @date 2019年8月28日下午2:53:49
 * @version 1.0.0
 * 离线Criteria练习
 */
public class CriteriaDemo2 {
	@SuppressWarnings("rawtypes")
	@Test
	public void fun1(){
		//Service/web层
		DetachedCriteria dc = DetachedCriteria.forClass(Customer.class);
		
		dc.add(Restrictions.idEq(3l));//拼装条件(全部与普通Criteria一致)
		
		Session session = HibernateUtils.openSession();
		Transaction tx = session.beginTransaction();
		
		Criteria c = dc.getExecutableCriteria(session);
		List list = c.list();
		
		System.out.println(list);
		
		tx.commit();
		session.close();
	}
}
